﻿using System;
using DotNetNuke.Entities.Users;

namespace DotNetNuke.Modules._2DoTasks.Components
{
    public class UnitOfWork : IDisposable
    {
        private bool disposed = false;
        private UserInfo _currentUser = null;
        private int _portalId, _moduleId;

        #region "Properties"

        internal UserInfo CurrentUser
        {
            get
            {
                return _currentUser;
            }
        }

        internal int PortalId
        {
            get
            {
                return _portalId;
            }
        }

        internal int ModuleId
        {
            get
            {
                return _moduleId;
            }
        }

        #endregion "Properties"

        public UnitOfWork(int portalId, int moduleId)
        {
            _portalId = portalId;
            _moduleId = moduleId;
            _currentUser = UserController.GetCurrentUserInfo();
        }

        public UnitOfWork(int portalId, UserInfo currentUser)
        {
            _portalId = portalId;
            _currentUser = currentUser;
        }

        #region "Disposable"

        public void Dispose()
        {
            Dispose(true);

            // This object will be cleaned up by the Dispose method.
            // Therefore, you should call GC.SupressFinalize to
            // take this object off the finalization queue
            // and prevent finalization code for this object
            // from executing a second time.
            GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!this.disposed)
            {
                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                }

                // Clean up all native resources

                // Note disposing has been done.
                disposed = true;
            }
        }

        ~UnitOfWork()
        {
            Dispose(false);
        }

        #endregion "Disposable"
    }
}